package LC;

import java.util.LinkedList;

/**
 * @ClassName JZ62
 * @Description: TODO
 * @Author hl
 * @Date 2020/9/14
 * @Version V1.0
 **/
public class JZ62 {
    public int lastRemaining(int n, int m) {
        LinkedList<Integer> list=new LinkedList<>();
        for(int i=0;i<n;i++){
            list.add(i);
        }
        int remove=0;
        while(list.size()>1){
            remove=(remove+m-1)%list.size();
            list.remove(remove);
        }
        return list.get(0);

    }
}
